home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / AMOS / AMOSList-0697 / AMOSLIST / text0167.txt < prev    next >
Encoding:
Text File  |  1997-07-03  |  1.4 KB  |  64 lines

  1. Hi,
  2.  
  3. Try this:
  4.  
  5.     _zoom=256
  6.     lens=256
  7.     distance=_zoom-z
  8.  
  9.     X_Screen = (lens*(x/distance))+cx
  10.     Y_Screen = cy-(lens*(y/distance))
  11.  
  12. Where cx and cy are the coordinates of the centre of the screen.
  13. This method seems to cause some problems when objects are "behind" the
  14. camera, so be careful not to draw any point with distance<=0 (and 0 will mess
  15. up the division anyway).
  16.  
  17. This gives you a 3D system with Cartesian x and y axes plus a z-axis sticking
  18. out towards you. Crappy ASCII diagram follows:
  19.  
  20.           Y
  21.           |
  22.           |
  23.           |
  24.           0----------> X
  25.          /
  26.         /
  27.        Z
  28.  
  29.  
  30. While I'm at it, here's some rotation formulae:
  31.  
  32. To rotate a point about the world Y-axis:
  33.  
  34.             sang=sin(angle) : cang=cos(angle)            
  35.             tempx = (x * cang) + (z * sang)
  36.             tempz = (z * cang) - (x * sang)
  37.             y=tempy
  38.             z=tempz
  39.  
  40. (obviously some of these are floats, so stick the necessary # signs in in
  41. Amos)
  42.  
  43. To rotate a point about the camera Y-axis (ie when you turn, rotate the
  44. object
  45. around the camera in the opposite direction):
  46.  
  47.             dz = z - _zoom
  48.             tempx = (x * cang) + (dz * sang)
  49.             tempz = ((dz * cang) - (x * sang)) + _zoom
  50.             x=tempx
  51.             y=tempy
  52.  
  53. Rotations about the other axes can be derived from these. If you're still
  54. stuck,
  55. let me know and I'll see if I can help you further.
  56.  
  57. Cheers,
  58.  
  59. Matt Craven
  60. Hedgehog Software
  61. mcraven629@aol.com
  62.  
  63.  
  64.